module tcp_timer(
    input   i_clk,      //125M
    input   i_rst,
    output  o_flag_500ms,
    output  o_flag_250ms
);

    logic   [23:0]  count_1ms;
    logic           flag_1ms;

    logic   [23:0]  count_250ms;
    logic   [23:0]  count_500ms;
    logic   flag_500ms;
    logic   flag_250ms;

    assign o_flag_500ms = flag_500ms;
    assign o_flag_250ms = count_250ms;
    

    always_ff @( posedge i_clk ) begin
        if(i_rst)
            count_1ms <= 0;
        else if(count_1ms == 24'd125000-1)
            count_1ms <= 0;
        else 
            count_1ms <= count_1ms + 1;  
    end


    always_ff @( posedge i_clk ) begin
        if(i_rst)
            flag_1ms <= 0;
        else if(count_1ms == 24'd125000-1)
            flag_1ms <= 1;
        else 
            flag_1ms <= 0;  
    end

    always_ff @( posedge i_clk ) begin
        if(i_rst)
            count_250ms <= 0;
        else if(count_250ms == 8'd250-1)
            count_250ms <= 0;
        else if(flag_1ms)
            count_250ms <= count_250ms + 1;  
        else 
            count_250ms <= count_250ms;  
    end


    always_ff @( posedge i_clk ) begin
        if(i_rst)
            flag_250ms <= 0;
        else if(count_250ms == 8'd250-1)
            flag_250ms <= 1;
        else 
            flag_250ms <= 0;  
    end

    always_ff @( posedge i_clk ) begin
        if(i_rst)
            count_500ms <= 0;
        else if(count_500ms == 9'd500-1)
            count_500ms <= 0;
        else if(flag_1ms)
            count_500ms <= count_500ms + 1;  
        else 
            count_500ms <= count_500ms;  
    end


    always_ff @( posedge i_clk ) begin
        if(i_rst)
            flag_500ms <= 0;
        else if(count_500ms == 9'd500-1)
            flag_500ms <= 1;
        else 
            flag_500ms <= 0;  
    end

    



endmodule